<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@include file="/WEB-INF/jsp/common/taglibs.jspf"%>
<es:contentHeader />
<div class="panel">

	<ul class="nav nav-tabs">
		<shiro:hasPermission name="wei:tribune:create">
			<c:if test="${op eq '新增'}">
				<li ${op eq '新增' ? 'class="active"' : ''}><a
					href="${ctx}/wei/tribune/create?BackURL=<es:BackURL/>"> <i
						class="icon-file-alt"></i> 新增
				</a></li>
			</c:if>
		</shiro:hasPermission>

		<c:if test="${not empty m.id}">
			<li ${op eq '查看' ? 'class="active"' : ''}><a
				href="${ctx}/wei/tribune/${m.id}?BackURL=<es:BackURL/>"> <i
					class="icon-eye-open"></i> 查看
			</a></li>
			<shiro:hasPermission name="wei:tribune:update">
				<li ${op eq '修改' ? 'class="active"' : ''}><a
					href="${ctx}/wei/tribune/${m.id}/update?BackURL=<es:BackURL/>">
						<i class="icon-edit"></i> 修改
				</a></li>
			</shiro:hasPermission>
			<shiro:hasPermission name="wei:tribune:delete">
				<li ${op eq '删除' ? 'class="active"' : ''}><a
					href="${ctx}/wei/tribune/${m.id}/delete?BackURL=<es:BackURL/>">
						<i class="icon-trash"></i> 删除
				</a></li>
			</shiro:hasPermission>
		</c:if>
		<li><a href="<es:BackURL/>" class="btn btn-link"> <i
				class="icon-reply"></i> 返回
		</a></li>
	</ul>

	<form:form id="editForm" method="post" commandName="m"
		cssClass="form-horizontal">
		<es:showGlobalError commandName="m" />

		<form:hidden path="id" />
		<div class="control-group">
			<form:label path="tname" cssClass="control-label">发帖名称</form:label>
			<div class="controls">
				<form:input path="tname" cssClass="input-xxlarge validate[required]"
					placeholder="5到10个字母、数字、下划线" />
			</div>
		</div>

		<div class="control-group">
			<form:label path="ttype" cssClass="control-label">发帖类别</form:label>
			<div class="controls input-append">
				<form:select path="ttype" cssClass=" validate[required]">
					<form:option label="请选择" value="" />
					<form:options items="${category}" itemLabel="info" />
				</form:select>
			</div>
		</div>

		<div class="control-group">
			<form:label path="userName" cssClass="control-label">发帖用户</form:label>
			<div class="controls">
				<form:input path="userName" cssClass="validate[required]"
					placeholder="5到10个字母、数字、下划线" />
			</div>
		</div>

		<div class="control-group">
			<form:label path="tcontent" cssClass="control-label">发帖内容</form:label>
			<div class="controls">
				<c:choose>
					<c:when test="${op ne '查看'}">
						<form:textarea path="tcontent" cssClass="validate[required]"
							cssStyle="width: 550px;height: 250px;" />
					</c:when>
					<c:otherwise>
                        ${m.tcontent}
                    </c:otherwise>
				</c:choose>
			</div>
		</div>

		<div class="control-group">
			<form:label path="tgood" cssClass="control-label">赞</form:label>
			<div class="controls">
				<form:input path="tgood"
					cssClass="validate[required,custom[integer]]"
					placeholder="请输入整数且大于等于0的数字" />
			</div>
		</div>
		<div class="control-group">
			<form:label path="tbad" cssClass="control-label">被鄙视</form:label>
			<div class="controls">
				<form:input path="tbad"
					cssClass="validate[required,custom[integer]]"
					placeholder="请输入整数且大于等于0的数字" />
			</div>
		</div>


		<div class="control-group">
			<form:label path="show" cssClass="control-label">是否显示</form:label>
			<div class="controls inline-radio">
				<form:radiobuttons path="show" items="${booleanList}"
					itemLabel="info" itemValue="value" cssClass="validate[required]" />
			</div>
		</div>


		<c:if test="${op eq '新增'}">
			<c:set var="icon" value="icon-file-alt" />
		</c:if>
		<c:if test="${op eq '修改'}">
			<c:set var="icon" value="icon-edit" />
		</c:if>
		<c:if test="${op eq '删除'}">
			<c:set var="icon" value="icon-trash" />
		</c:if>

		<div class="control-group">
			<div class="controls">
				<button type="submit" class="btn btn-primary">
					<i class="${icon}"></i> ${op}
				</button>
				<a href="<es:BackURL/>" class="btn"> <i class="icon-reply"></i>
					返回
				</a>
			</div>
		</div>

	</form:form>
</div>
<es:contentFooter />
<%@include file="/WEB-INF/jsp/common/import-editor-js.jspf"%>
<script type="text/javascript">
	$(function() {
		<c:choose>
		<c:when test="${op eq '删除'}">
		//删除时不验证 并把表单readonly
		$.app.readonlyForm($("#editForm"), false);
		</c:when>
		<c:when test="${op eq '查看'}">
		$.app.readonlyForm($("#editForm"), true);
		</c:when>
		<c:otherwise>
		//自定义ajax验证  ajax[ajaxNameCall] 放到验证规则的最后（放到中间只有当submit时才验证）
		$.validationEngineLanguage.allRules.ajaxNameCall = {
			"url" : "${ctx}/showcase/sample/validate",
			//动态提取的数据。验证时一起发送
			extraDataDynamic : [ '#id' ],
			//验证失败时的消息
			//"alertText": "* 该名称已被其他人使用",
			//验证成功时的消息
			//"alertTextOk": "该名称可以使用",
			"alertTextLoad" : "* 正在验证，请稍等。。。"
		};
		$.validationEngineLanguage.allRules.username = {
			"regex" : /^\w{5,10}$/,
			"alertText" : "* 5到10个字母、数字、下划线"
		};
		var validationEngine = $("#editForm").validationEngine();
		<es:showFieldError commandName="m"/>
		</c:otherwise>
		</c:choose>
		//
		var editor = KindEditor.create('textarea[name="tcontent"]', {
			themeType : 'simple',
			uploadJson : '${ctx}/kindeditor/upload',
			fileManagerJson : '${ctx}/kindeditor/filemanager',
			allowFileManager : true,
			afterBlur : function() {
				this.sync();
			}
		});
	});
</script>